doctor_info = []


function initialize(){

	function on_doctor_data(receved_data){
		total_info = JSON.parse(receved_data)
		doctor_info = total_info[0]
		
		display_operation_hours_view()
	}

	initialize_ajax("/get_doctor_data", on_doctor_data)
}

function save_operation_hour(){
	doctor_info['monday_start'] = document.getElementById('monday_start').value
	doctor_info['monday_end'] = document.getElementById('monday_end').value
	doctor_info['tuesday_start'] = document.getElementById('tuesday_start').value
	doctor_info['tuesday_end'] = document.getElementById('tuesday_end').value
	doctor_info['wednesday_start'] = document.getElementById('wednesday_start').value
	doctor_info['wednesday_end'] = document.getElementById('wednesday_end').value
	doctor_info['thursday_start'] = document.getElementById('thursday_start').value
	doctor_info['thursday_end'] = document.getElementById('thursday_end').value
	doctor_info['friday_start'] = document.getElementById('friday_start').value
	doctor_info['friday_end'] = document.getElementById('friday_end').value
	doctor_info['saturday_start'] = document.getElementById('saturday_start').value
	doctor_info['saturday_end'] = document.getElementById('saturday_end').value
	doctor_info['sunday_start'] = document.getElementById('sunday_start').value
	doctor_info['sunday_end'] = document.getElementById('sunday_end').value
	doctor_info['exception_days'] = document.getElementById('exception_id').value

	function on_doctor_update(receved_data){
		retVal = JSON.parse(receved_data)
		if(retVal['type'] == 'error'){
			alert(retVal['msg'])
			return
		}else{
			alert('schedule saved')
		}
		document.location.reload()
	}

	doc_dat = specialToSafe(JSON.stringify(doctor_info))
	cmd = '/update_doctor_info' + document.location.search + '&doctor_data=' + doc_dat
	initialize_ajax(cmd, on_doctor_update)
}

function display_operation_hours_view(){

	content = '<div id=content_id class=content>'
	content += '<div id=inner_content_id class=inner_content style="overflow:auto;">'
	content += 'Set Operational Hour from start time to end time. Example : 8:00am, closed<br><br>'
	content += '<div style="margin-left:50px;border: 0px solid #dddddd;margin-bottom:10px;">'
	content += '<table>'
	content += 		add_input('Monday : ', 'monday_start', '<tr>','', doctor_info['monday_start'])
	content += 		add_input('to ', 'monday_end', '','</tr>', doctor_info['monday_end'])
	content += 		add_input('Tuesday : ', 'tuesday_start', '<tr>','', doctor_info['tuesday_start'])
	content += 		add_input('to ', 'tuesday_end', '','</tr>', doctor_info['tuesday_end'])
	content += 		add_input('Wednesday : ', 'wednesday_start', '<tr>','', doctor_info['wednesday_start'])
	content += 		add_input('to ', 'wednesday_end', '','</tr>', doctor_info['wednesday_end'])
	content += 		add_input('Thursday : ', 'thursday_start', '<tr>','', doctor_info['thursday_start'])
	content += 		add_input('to ', 'thursday_end', '','</tr>', doctor_info['thursday_end'])
	content += 		add_input('Friday : ', 'friday_start', '<tr>','', doctor_info['friday_start'])
	content += 		add_input('to ', 'friday_end', '','</tr>', doctor_info['friday_end'])
	content += 		add_input('Saturday : ', 'saturday_start', '<tr>','', doctor_info['saturday_start'])
	content += 		add_input('to ', 'saturday_end', '','</tr>', doctor_info['saturday_end'])
	content += 		add_input('Sunday : ', 'sunday_start', '<tr>','', doctor_info['sunday_start'])
	content += 		add_input('to ', 'sunday_end', '','</tr>', doctor_info['sunday_end'])
	Excpt_txt = 	'Exceptions : month/day separated by comma, example: 1/1,12/25,12/24'
	content += 		add_text_area(Excpt_txt,'exception_id','<tr>','</tr>', doctor_info['exception_days'])
	pButton = 		pretty_button('save_operation_hour()', 'Save', 100, 30, '')
	content += 		addItem(pButton, 'colspan=4 style="text-align:right;"', '<tr>','</tr>')

	content += '</table>'
	content += '</div>'

	content += '</div></div>'
	document.getElementById('web_content').innerHTML = content
}
